package com.topInterview;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/20 16:13
 */
public class Leecode69 {
    public static int mySqrt(int x) {
        if(x == 0){
            return 0;
        }

        if(x<3){
            return 1;
        }
        long left = 1;
        long right = x;
        long res = 1;
        long mid = 0;
        while (left <= right) {
            mid = (left + right) / 2;
            if (mid * mid > x) {
                right = mid - 1;
            } else {
                res = mid;
                left = mid + 1;
            }
        }
        return (int)res;
    }

    public static void main(String[] args) {
        mySqrt(5);
    }
}
